package com.gitee.wsl.compose.ui.richtext.edit.model.paragraph.type

import androidx.compose.ui.text.ParagraphStyle
import com.gitee.wsl.compose.ext.text.DefaultParagraphStyle
import com.gitee.wsl.compose.ui.richtext.edit.annotation.ExperimentalRichTextApi
import com.gitee.wsl.compose.ui.richtext.edit.model.span.RichSpan
import com.gitee.wsl.compose.ui.richtext.edit.model.RichTextConfig
import com.gitee.wsl.compose.ui.richtext.edit.model.paragraph.RichParagraph

interface ParagraphType {

    fun getStyle(config: RichTextConfig): ParagraphStyle

    val startRichSpan: RichSpan

    fun getNextParagraphType(): ParagraphType

    fun copy(): ParagraphType

    companion object {


        val Default = DefaultParagraphType()

        fun default() = DefaultParagraphType()
    }
}

val ParagraphType.startText : String get() = startRichSpan.text

class DefaultParagraphType : ParagraphType {

    //private val style: ParagraphStyle = ParagraphStyle()

    override fun getStyle(config: RichTextConfig): ParagraphStyle = DefaultParagraphStyle

    @OptIn(ExperimentalRichTextApi::class)
    override val startRichSpan: RichSpan = RichSpan(paragraph = RichParagraph(type = this))

    override fun getNextParagraphType(): ParagraphType = ParagraphType.default()

    override fun copy(): ParagraphType = ParagraphType.default()

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (other !is DefaultParagraphType) return false

        return true
    }

    override fun hashCode(): Int {
        return 0
    }
}